﻿//  --------------------------------
//  Copyright (c) AW Systems, Inc. All rights reserved.
//  This source code is made available under the terms of the Microsoft Public License (Ms-PL)
//  http://www.codeplex.com/SLAM/license
//  ---------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Slam.Configuration;
using Slam.Data;
using Slam.Logging;
using Slam.SharePoint;
using Microsoft.SharePoint;
using System.Collections;

namespace Slam.Events
{
	/// <summary>
	/// ListItemUpdater updates an item to SLAM's datasource(s) when a new List Item is updated in a 
	/// List configured to be managed by SLAM in SharePoint.
	/// 
	/// ListItemUpdater is the default implementation of SLAM's IItemUpdater that uses a List Item's
	/// List to determine its behavior.
	/// </summary>
	public class ListItemUpdater : IItemUpdater
	{
		#region Private State 
	   
		private IDataServices _dataServices;
		private IConfigurationManager _configuration;        
		private ILogger _logger;

		/// <summary>
		/// Regex pattern to validate Guid strings
		/// </summary>
		private static Regex _guidRegex = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);

		#endregion

		#region Constructors

		public ListItemUpdater(IDataServices dataServices, IConfigurationManager configuration, ILogger logger)
		{
			_dataServices = dataServices;
			_configuration = configuration;            
			_logger = logger;            
		}

		#endregion

		#region IItemUpdater Members

		public virtual bool Update(SPListItem listItem)
		{
			return DefaultEvents.Update(listItem, _dataServices, _configuration, _logger, "Update LI");
		}

		#endregion
	}
}
